@extends('manage._layout')
@section('page-title')
    修改一级菜单
@stop
@section('page-breadcrumbs')
    <li>
        <a href="{{route('first_menu_list')}}" title="">
            一级菜单管理
        </a>
    </li>
    <li class="current">
        <a href="javascript:;" title="">
            修改
        </a>
    </li>
@stop
@section('page-buttons')
    <li>
        <a href="{{route('first_menu_list')}}" title="">
            <i class="icon-reply"></i>
            <span>返回</span>
        </a>
    </li>
@stop

@section('page-content')
    <form class="form-horizontal" role="form" action="" enctype="multipart/form-data">
        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">菜单名称</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" name="name" id="name"
                    value="{{$data->name}}"   placeholder="请输入菜单名称">
            </div>
        </div>
        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">图标样式</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" name="class" id="class"
                       value="{{$data->class}}"  placeholder="请输入图标样式">
            </div>
        </div>

        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">排序</label>
            <div class="col-sm-2">
                <input type="text" class="form-control" name="sort" id="sort"
                       value="{{$data->sort}}"    placeholder="请输入排序">
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-default" id="sub">修改</button>
            </div>
        </div>
        <input type="hidden" id="first_menu_id" value="{{$data->id}}"/>
    </form>
    <script>
        $(document).ready(function () {
            $('#sub').click(function () {
                if ($('#name').val() == '') {
                    layer.alert('请填写一级菜单名称');
                    return false;
                }
                if ($('#class').val() == '') {
                    layer.alert('请填写图标样式');
                    return false;
                }
                var postdata = {
                    name: $('#name').val(),
                    id: $('#first_menu_id').val(),
                    class: $('#class').val(),
                    sort: $('#sort').val(),

                };

                $.ajax({
                    type: 'POST',
                    url: '{{URL::route('first_menu_edit_post')}}',
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                    data: postdata,
                    success: function (res) {
                        if (res.error == 0) {
                            location.href = '{{URL::route('first_menu_list')}}';
                        } else {
                            layer.alert(res.message);
                        }
                    },
                    error: function(XMLHttpRequest) {
                        if(XMLHttpRequest.status==403){
                            layer.alert(noAccessMsg);
                        }else{
                            layer.alert(otherErrorMsg);
                        }
                    }
                });
            });
            //////////////////////////


        });
    </script>
@stop